package com.rabbit.mq.impl;

import com.rabbit.config.MqProducerProperties;
import com.rabbit.entity.Notice;
import com.rabbit.mq.NoticeTopicProducer;
import com.rabbit.route.RoutingKey;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * @author yuhuan
 * @date 2025/4/18
 */
@Service
public class NoticeTopicProducerImpl implements NoticeTopicProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private MqProducerProperties mqProperties;

    @Override
    public void sendHotelMessage(Notice message) {
        message.setDataId(UUID.randomUUID().toString());
        System.out.println(String.format("正在推送酒店主题通知[%s]，msg: %s", message.getCode(), message));
        rabbitTemplate.convertAndSend(mqProperties.getTopicExchangeName(), RoutingKey.MQ_KEY_HOTEL_TOPIC, message);
    }

    @Override
    public void sendAdminMessage(Notice message) {
        message.setDataId(UUID.randomUUID().toString());
        System.out.println(String.format("正在推送管理员主题通知[%s]，msg: %s", message.getCode(), message));
        rabbitTemplate.convertAndSend(mqProperties.getTopicExchangeName(), RoutingKey.MQ_KEY_ADMIN_TOPIC, message);
    }
}
